
function [relfreq relcount count bandwidth total]= relfreq_varyingbin(donationc);
        
n=301;
% from 0 to 300: 301 integers
count= zeros(n,1); 
donationc=round(donationc);
    for i=1:n;
        count(i,1)= sum(donationc(:) == i-1); % sum occurences in donationc of 0 to 300
    end
    total=sum(count); % sample size

bandwidth=zeros(301,1); 
ind=(1:301)';
one=[(1:31) (36:5:101) (111:10:191) 201 251 301]';
four= [(32:35) (37:40) (42:45) (47:50) (52:55) (57:60) (62:65) (67:70) (72:75) (77:80) (82:85) (87:90) (92:95) (97:100)]';
nine=[(102:110) (112:120) (122:130) (132:140) (142:150) (152:160) (162:170) (172:180) (182:190) (192:200) (242:250) (292:300)]';
ten=[(202:241) (252:291)]';
%%
bandwidth(ismember(ind, one))= 1;
bandwidth(ismember(ind, four))= 4;
bandwidth(ismember(ind, nine))=9;
bandwidth(ismember(ind, ten))=10;

a1=(31:5:96);
for i= 1:length(a1);
   count((a1(i)+1):(a1(i)+4),1)= sum(count((a1(i)+1):(a1(i)+4),1));
end 

a2=(101:10:191);
for i= 1:length(a2);
   count((a2(i)+1):(a2(i)+9),1)= sum(count((a2(i)+1):(a2(i)+9),1));
end 

a3=(202:10:292);
for i= 1:length(a3);
    if a3(i)~= 242 & a3(i)~= 292;
    count(a3(i):(a3(i)+9),1)= sum(count(a3(i):(a3(i)+9),1));
    else
        count(a3(i):(a3(i)+8),1)= sum(count(a3(i):(a3(i)+8),1));
    end
end 

relcount=count./bandwidth;

relfreq= relcount./total;
end


